package com.itguigu.advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * 使用普通方式进行事务模拟
 */

//@Component
//@Aspect
public class TxAdvice {

    @Before("com.itguigu.pointcut.mypointcut.pc1()")
    public void begin() {
        System.out.println("开启事务");
    }

    @After("com.itguigu.pointcut.mypointcut.pc1()")
    public void commit() {
        System.out.println("提交事务");
    }

    @AfterThrowing(value = "com.itguigu.pointcut.mypointcut.pc1()", throwing = "e")
    public void rollback(JoinPoint point, Throwable e) {
        System.out.println(point.getSignature().getName() + ":回滚事务" + e.getMessage());
    }


}
